package com.nega.modules.thread;

import com.nega.commons.model.SearchResult;
import com.nega.modules.service.SpiderService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * @Author: Garcia
 * @CreateDate: 2019/5/13 13:48
 * @Description: what it is class?
 */
@Slf4j
public class SpiderThreadResult implements Callable<List<SearchResult>> {

    private SpiderService spiderService;

    private String text;

    public SpiderThreadResult() {

    }

    public SpiderThreadResult(SpiderService spiderService, String text) {
        this.spiderService = spiderService;
        this.text = text;
    }

    @Override
    public List<SearchResult> call() {
        try {
            List<SearchResult> result = spiderService.getResultInfo(text);
            if (result == null || result.size() < 1) {
                return new ArrayList<>();
            }
            return result;
        } catch (Exception e) {
            log.error("线程执行异常", e);
        }
        return new ArrayList<>();
    }
}
